package com.face.console.controller;

import com.face.console.feign.Tfeign;
import com.face.console.pojo.dto.FieldDto;
import com.face.console.service.FieldDtoService;
import com.face.console.tools.BaseControoler;
import com.face.console.tools.Error;
import com.face.console.tools.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Description:
 * <p>
 * Created by Andy_Lau on 2020/12/27 23:50
 */
@RestController
@RequestMapping(value = "/api/field")
public class FieldController extends BaseControoler {

    @Autowired
    private FieldDtoService fieldDtoService;

    @Autowired
    private static Tfeign tfeign;
    @PostMapping(value = "/save")
    public R save(@RequestBody FieldDto request) {
        if (request != null) {
            fieldDtoService.insertField(request);
        }
        return R.success();
    }

    @PostMapping(value = "/{id}/field")
    public R getFieldById(@RequestParam("id") Long id) {
        return R.success(fieldDtoService.queryFieldById(id));
    }

    @PostMapping(value = "/list")
    public R getFieldById(@RequestBody FieldDto query) {
//        return R.success(fieldDtoService.fieldVos(query));
        System.out.println(tfeign.getStr());
        return R.success(tfeign.getStr());
    }


    @PostMapping(value = "/{id}/del")
    public R deleteByPrimaryKey(@RequestParam("id") Long id) {
        if (id != null && id != 0) {
            return fieldDtoService.deleteByPrimaryKey(id) == true ? R.success() : R.error();
        }
        return R.error(Error.参数为空异常);
    }

}
